#include    "backtofunc.h"


/************this part put at one idle file *******/
extern lv_obj_t *Function;
extern  lv_obj_t *tabview;
extern unsigned char Flag_new_page;
lv_anim_t anim;
lv_timer_t * Timer_delete=NULL;//this task is to dele some out function page

void del_page_delay(lv_timer_t * timer)
{
	lv_obj_t *obj;
	obj=(lv_obj_t *)timer->user_data;
	lv_obj_del(obj);
} 

//the implement of the close page animation
 void set_close_page_anim(void * var, int32_t v)
 {
	 lv_obj_set_height((lv_obj_t *)var, v);
 }


 void back_anim_Init(void){
	 lv_anim_init(&anim);
	 lv_anim_set_exec_cb(&anim, (lv_anim_exec_xcb_t) set_close_page_anim);

	 /*Length of the animation [ms]*/
	 lv_anim_set_time(&anim, 200);

	 /*Set start and end values. E.g. 0, 150*/
	 lv_anim_set_values(&anim, 240, 0);
 }


//switch the page from the current funcion page to the function selecting page
 void back_to_funcion(lv_obj_t*obj){
	back_anim_Init();
	//to create the function page and initialize the function page
	Function = lv_tabview_add_tab(tabview, "");
	lv_obj_set_scrollbar_mode(Function, LV_SCROLLBAR_MODE_OFF);
    Function_Init(Function);//create the function selecting page
	lv_tabview_set_act(tabview, 1, LV_ANIM_OFF);
	/*Set the "animator" function*/
	lv_anim_set_var(&anim, obj);
	lv_anim_start(&anim);
	Timer_delete=lv_timer_create(del_page_delay, 500, obj);//this del task will delete the current function 100ms later
	lv_timer_set_repeat_count(Timer_delete,1);//the timer will just execute one time
}

